﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Threading;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JHMVVMFramework;
using JHMVVMFramework.Task;

namespace JHMVVMFramework.Task
{
    public abstract class BaseTask<ResultType> : ITask<ResultType>
    {
        public event TaskComplatedEventHandler<ResultType> OnTaskComplated;
        public event TaskProgressChangedEventHandler OnProgressChanged;

        protected abstract ResultType ConvertResponseDate(object responseData); 

        protected virtual void FireOnTaskComplated(Dispatcher dispatcher,TaskComplatedEventArgs<ResultType> eventArg)
        {
            if (OnTaskComplated != null)
            {
                dispatcher.BeginInvoke(OnTaskComplated, this, eventArg);
            }
        }

        protected virtual void FireOnTaskComplated(TaskComplatedEventArgs<ResultType> eventArg)
        {
            if (OnTaskComplated != null)
            {
                OnTaskComplated(this, eventArg);
            }
        }

        protected virtual void FireOnProgressChanged(Dispatcher dispatcher, TaskProgressChangedEventArgs eventArg)
        {
            if (OnProgressChanged != null)
            {

                dispatcher.BeginInvoke(OnProgressChanged, this, eventArg);
            }
        }

        protected virtual void FireOnProgressChanged(TaskProgressChangedEventArgs eventArg)
        {
            if (OnProgressChanged != null)
            {
                OnProgressChanged(this, eventArg);
            }
        }

      
    }
}
